home *** CD-ROM | disk | FTP | other *** search
- /*
- * name.c - routines handling the "Name" window pane.
- */
-
- #include <quickdraw.h>
- #include <memory.h>
- #include <window.h>
- #include <toolutil.h>
- #include <packages.h>
- #include <control.h>
- #define ALLDIM 255 /* should be in control.h, but isn't */
- #include <font.h>
-
- #include "ival.h"
- #include "progerr.h"
-
- /*
- * nabuts[] - buttons for the "Name" window pane
- */
-
- #define NASTRS 136 /* STR# */
- #define NA_GIVE 0 /* "Give Name" */
- #define NA_COUNT 1
- static ControlHandle nabuts[NA_COUNT];
-
- /*
- * updown[] - the button column specifying interval direction.
- */
-
- #define UDSTRS 131 /* STR# of labels for up/down names */
- #define UD_ABOVE 0 /* index (not strid) of "above" */
- #define UD_BELOW 1 /* below */
- #define UD_COUNT 2 /* number of updown[] items */
- static ControlHandle updown[UD_COUNT];
-
- /*
- * itype[] - the button column specifying interval type.
- * Indexed by IT_* (see ival.h).
- */
-
- #define ITSTRS 132 /* STR# of labels for interval types */
- static ControlHandle itype[IT_COUNT];
-
- /*
- * isize[] - the button column specifying interval size.
- * Indexed by isizectl[degree].
- *
- * isizectl[] - indexed by a degree, isizectl[] gives an index into isize[].
- * Using isizectl, the interval size buttons don't have to be by order of degree.
- */
-
- #define ISSTRS 133 /* STR# of labels for interval sizes */
- #define IS_OCT 0 /* octave */
- #define IS_7th 1 /* seventh */
- #define IS_6th 2 /* sixth */
- #define IS_5th 3 /* fifth */
- #define IS_4th 4 /* fourth */
- #define IS_3rd 5 /* third */
- #define IS_2nd 6 /* second */
- #define IS_UNI 7 /* unison */
- #define IS_COUNT 8 /* number of isize[] items */
- static ControlHandle isize[IS_COUNT];
-
- static int isizectl[IS_COUNT] = {
- IS_UNI, IS_2nd, IS_3rd, IS_4th, IS_5th, IS_6th, IS_7th, IS_OCT
- };
-
- /*
- * fillname() - create the "name" window pane and its contents.
- */
-
- fillname()
- {
- Rect windrect; /* rect enclosing the window */
- short oldfont; /* original font of this port */
- short numstrs; /* number of strings in the current STR# resource*/
- Rect udrect; /* rect enclosing the updown[] buttons */
- Rect itrect; /* rect enclosing the itype[] buttons */
- Rect isrect; /* rect enclosing the isize[] buttons */
- Point delta; /* a temporary distance */
- short width; /* a width (in pixels) */
- Rect tmprect; /* a temporary variable */
-
- topLeft(windrect) = topLeft(windoc->portRect);
- botRight(windrect) = botRight(windoc->portRect);
-
- oldfont = thePort->txFont;
- TextFont(BUTTONFONT);
-
- /*
- * get the rects that bound the columns of interval name buttons:
- * The itype[] and updown[] buttons occupy one column.
- */
-
- udrect.top = 0;
- udrect.left = 0;
- udrect.right = udrect.left + strswidth(UDSTRS, &numstrs) + BUTEXTRAH;
- udrect.bottom = udrect.top + numstrs * (BUTHEIGHT + BUTVMARG);
-
- itrect.top = 0;
- itrect.left = 0;
- itrect.right = itrect.left + strswidth(ITSTRS, &numstrs) + BUTEXTRAH;
- itrect.bottom = itrect.top + numstrs * (BUTHEIGHT + BUTVMARG);
-
- isrect.top = 0;
- isrect.left = 0;
- isrect.right = isrect.left + strswidth(ISSTRS, &numstrs) + BUTEXTRAH;
- isrect.bottom = isrect.top + numstrs * (BUTHEIGHT + BUTVMARG);
- TextFont(oldfont);
-
- if (udrect.right < itrect.right) {
- udrect.right = itrect.right;
- }
- itrect.right = udrect.right;
- OffsetRect(&isrect, udrect.right + HMARGIN, 0);
- OffsetRect(&itrect, 0, isrect.bottom - itrect.bottom);
-
- /*
- * Now the columns are in the correct relative places.
- * Offset them to the appropriate place in the window,
- */
-
- delta.h = windrect.left + HMARGIN;
- delta.v = windrect.bottom - HMARGIN - BUTHEIGHT - HMARGIN;
- delta.h -= itrect.left;
- delta.v -= itrect.bottom;
-
- OffsetRect(&udrect, delta.h, delta.v);
- OffsetRect(&itrect, delta.h, delta.v);
- OffsetRect(&isrect, delta.h, delta.v);
-
- /*
- * define the global Rect enclosing the Name pane.
- */
-
- namerect.left = windrect.left + HMARGIN;
- namerect.right = isrect.right;
- namerect.top = isrect.top;
- namerect.bottom = windrect.bottom - HMARGIN;
-
- /*
- * Create the columns of Name controls.
- */
-
- delta.h = 0;
- delta.v = BUTHEIGHT + BUTVMARG;
- topLeft(tmprect) = topLeft(udrect);
- botRight(tmprect) = botRight(udrect);
- tmprect.bottom = tmprect.top + BUTHEIGHT;
- makeradcol(updown, RADPROCID, UDSTRS, &tmprect, delta.h, delta.v);
-
- topLeft(tmprect) = topLeft(itrect);
- botRight(tmprect) = botRight(itrect);
- tmprect.bottom = tmprect.top + BUTHEIGHT;
- makeradcol(itype, RADPROCID, ITSTRS, &tmprect, delta.h, delta.v);
-
- topLeft(tmprect) = topLeft(isrect);
- botRight(tmprect) = botRight(isrect);
- tmprect.bottom = tmprect.top + BUTHEIGHT;
- makeradcol(isize, RADPROCID, ISSTRS, &tmprect, delta.h, delta.v);
-
- /*
- * Put the miscellaneous button(s) in their appropriate place:
- * Name buttons are right justified just above the bottom.
- */
-
- width = strswidth(NASTRS, &numstrs) + BUTEXTRAH;
- tmprect.left = namerect.right - (width + BUTHMARG) * numstrs;
- tmprect.right = tmprect.left + width;
- tmprect.bottom = namerect.bottom;
- tmprect.top = tmprect.bottom - BUTHEIGHT;
- delta.h = width + BUTHMARG;
- delta.v = 0;
- makeradcol(nabuts, BUTPROCID, NASTRS, &tmprect, delta.h, delta.v);
-
- TextFont(oldfont);
- }
-
- /*
- * newname() - reset the name controls, based on the new test state.
- */
-
- newname()
- {
- short i;
- int is_above;
-
- /*
- * always give the above/below buttons
- */
-
- if (curtone[1].degree > curtone[0].degree) {
- is_above = TRUE;
- } else if (curtone[1].degree < curtone[0].degree) {
- is_above = FALSE;
- } else if (curtone[1].chrome >= curtone[0].chrome) {
- is_above = TRUE;
- } else {
- is_above = FALSE;
- }
-
- if (is_above) {
- SetCtlValue(updown[UD_ABOVE], 1);
- SetCtlValue(updown[UD_BELOW], 0);
- } else {
- SetCtlValue(updown[UD_ABOVE], 0);
- SetCtlValue(updown[UD_BELOW], 1);
- }
-
- /*
- * clear out the type and size buttons
- */
-
- for (i = 0; i < IT_COUNT; ++i) {
- HiliteControl(itype[i], 0);
- SetCtlValue(itype[i], 0);
- }
- for (i = 0; i < IS_COUNT; ++i) {
- HiliteControl(isize[i], 0);
- SetCtlValue(isize[i], 0);
- }
-
- /*
- * Set the appropriate buttons (based on who does what).
- */
-
- if (!progtasks.name) {
- HiliteControl(nabuts[NA_GIVE], 0);
- isizeshown = FALSE;
- itypeshown = FALSE;
- } else {
- HiliteControl(nabuts[NA_GIVE], ALLDIM);
- SetCtlValue(itype[curitype], 1);
- itypeshown = TRUE;
- SetCtlValue(isize[isizectl[curisize]], 1);
- isizeshown = TRUE;
- }
- }
-
- /*
- * namepress() - handle a button-press in the Name pane.
- */
-
- namepress(whichcontrol)
- ControlHandle whichcontrol;
- {
- short oldvalue;
- short i;
-
- /*
- * find which button (and class of button) was pressed.
- */
-
- for (i = 0; i < NA_COUNT; ++i) {
- if (whichcontrol == nabuts[i]) {
-
- /*
- * "Give" button. Give the user one part of the interval.
- */
-
- if (!isizeshown) {
- SetCtlValue(isize[isizectl[curisize]], 1);
- isizeshown = TRUE;
- } else if (!itypeshown) {
- SetCtlValue(itype[curitype], 1);
- itypeshown = TRUE;
-
- HiliteControl(nabuts[NA_GIVE], ALLDIM);
- }
- break;
- }
- }
- for (i = 0; i < UD_COUNT; ++i) {
- if (whichcontrol == updown[i]) {
- /* ignore it */
- break;
- }
- }
- for (i = 0; i < IT_COUNT; ++i) {
- if (whichcontrol == itype[i]) {
-
- /*
- * An itype press.
- * If they got it right, light that button;
- * otherwise, dim that button.
- */
-
- if (!itypeshown) {
- if (i == curitype) {
- SetCtlValue(itype[curitype], 1);
- itypeshown = TRUE;
-
- if (isizeshown) {
- HiliteControl(nabuts[NA_GIVE], ALLDIM);
- }
- } else {
- if (!isizeshown) {
- /*XXX deal with enharmonic equivalents */
- }
- HiliteControl(itype[i], ALLDIM);
- }
- }
- break;
- }
- }
- for (i = 0; i < IS_COUNT; ++i) {
- if (whichcontrol == isize[i]) {
-
- /*
- * An isize press.
- * If they got it right, light that button;
- * otherwise, dim that button.
- */
-
- if (!isizeshown) {
- if (i == isizectl[curisize]) {
- SetCtlValue(isize[isizectl[curisize]], 1);
- isizeshown = TRUE;
-
- if (itypeshown) {
- HiliteControl(nabuts[NA_GIVE], ALLDIM);
- }
- } else {
- if (!itypeshown) {
- /*XXX deal with enharmonic equivalents */
- }
- HiliteControl(isize[i], ALLDIM);
- }
- }
- break;
- }
- }
- }
-